package per.dj.testpro.service.impl;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import per.dj.testpro.entity.protocol.*;
import per.dj.testpro.model.*;
import per.dj.testpro.service.DataService;
import per.dj.testpro.utils.CommonUtils;
import per.dj.testpro.utils.common.Constant;
import per.dj.testpro.utils.common.HttpRequest;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class DataServiceImpl extends BaseServiceImpl implements DataService{

    private final static Logger LOGGER = LoggerFactory.getLogger(DataServiceImpl.class);

    private static DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");

    private ConcurrentLinkedQueue<Message> dataQueue = new ConcurrentLinkedQueue<Message>();

    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);

    private Thread processRealDataThread;

    private Boolean startProcess = true;

    public void processData(Message tm) {
        dataQueue.add(tm);
    }

    public DataServiceImpl() {
        processRealDataThread = new Thread(new Runnable() {
            public void run() {
                ProcessRealDataThreadFunc();
            }
        });
        processRealDataThread.start();
    }

    private void ProcessRealDataThreadFunc() {

        while (startProcess) {
            try {
                Message tm = dataQueue.poll();//从队列中删除第一个元素
                final List<Message> msgList = new ArrayList<Message>();
                while (tm != null) {
                    msgList.add(tm);
                    if (msgList.size() > 100)
                        break;
                    tm = dataQueue.poll();
                }
                if (msgList.size() > 0) {
                    LOGGER.info("Ack中List大小:" + msgList.size());
                    fixedThreadPool.execute(new Runnable() {
                        @Override
                        public void run() {
                            handleDataList(msgList);
                        }
                    });
                }
            } catch (Exception ex) {
                LOGGER.error(ex.getMessage(), ex);
                continue;
            }

            try {
                Thread.sleep(20L);
            } catch (InterruptedException e1) {
                LOGGER.error(e1.getMessage(), e1);
                continue;
            }
        }
    }

    private void handleDataList(List<Message> msgList){
        for (Message tm : msgList) {
            handleData(tm);
        }
    }

    private void handleData(Message tm){
        //注册

        if(tm.getHeader().getMessageId() == 0x01){
            terminalRegister(tm);
        //心跳
        }else if(tm.getHeader().getMessageId() == 0x04){
            terminalTime(tm);
        //设置工作模式
        }else if(tm.getHeader().getMessageId() == 0x05){
            terminalSetWorkMode(tm);
        //充电使能
        }else if(tm.getHeader().getMessageId() == 0x06){
            terminalChargeEnable(tm);
        //停止充电
        }else if(tm.getHeader().getMessageId() == 0x07){
            terminalChargeStop(tm);
        //开始交易
        }else if(tm.getHeader().getMessageId() == 0x08){
            terminalStartTrans(tm);
        //结束交易
        }else if(tm.getHeader().getMessageId() == 0x09){
            terminalEndTrans(tm);
        //设置端口启用状态
        }else if(tm.getHeader().getMessageId() == 0x0A){
            terminalSetPortMode(tm);
        //故障上报
        }else if(tm.getHeader().getMessageId() == 0x0B){
            terminalErrorUpdate(tm);
        //设置网络参数
        }else if(tm.getHeader().getMessageId() == 0x0C){
            terminalSettingNetwork(tm);
        //远程升级
        }else if(tm.getHeader().getMessageId() == 0x0D){
            terminalRemoteUpdate(tm);
        }

    }

    //远程升级
    private void terminalRemoteUpdate(Message msg){
        Qy_0D qy0D = (Qy_0D) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy0D.getReturnRes();
        try {
            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //设置网络参数
    private void terminalSettingNetwork(Message msg){
        Qy_0C qy0c = (Qy_0C) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy0c.getReturnRes();
        try {
            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //故障上报
    private void terminalErrorUpdate(Message msg){
        Qy_0B qy0B = (Qy_0B) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        List<Qy_0B_SON> qy0BSonsList  = qy0B.getQy0BSonsList();

        //主板故障码
        String boardFailureCode = qy0B.getBoardFailureCode();
        try {
            ErrorInfo errorInfo = null;
            Date dt = new Date();
            if(!"00000000".equals(boardFailureCode)){
                errorInfo.setImeiNo(simId);
                errorInfo.setStationError(boardFailureCode);
                errorInfo.setCreateTime(dt);
                errorInfoMapper.insertSelective(errorInfo);
            }
            String portError = "";
            int portNum = qy0B.getPortNum();
            Qy_0B_SON qy0BSon = null;
            for(int i=0;i<portNum;i++){
                qy0BSon = qy0BSonsList.get(i);
                portError = qy0BSon.getPortError();
                if(!"00000000".equals(portError)){
                    errorInfo = new ErrorInfo();
                    errorInfo.setImeiNo(simId);
                    errorInfo.setPortNo(i+1);
                    errorInfo.setPortError(portError);
                    errorInfo.setCreateTime(dt);
                    errorInfoMapper.insertSelective(errorInfo);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //设置端口模式
    private void terminalSetPortMode(Message msg){
        Qy_0A qy0A = (Qy_0A) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy0A.getReturnRes();
        try {
            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);


                    int portStatus = qy0A.getPortStatus();
                    RechargeStationInfo rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
                    if(rechargeStationInfo!=null){
                        if(portStatus==0){
                            rechargeStationInfo.setPortIdleNum(rechargeStationInfo.getPortIdleNum()-1);
                        }else{
                            rechargeStationInfo.setPortIdleNum(rechargeStationInfo.getPortIdleNum()+1);
                        }
                        rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
                    }

                    RechargePortInfo rechargePortInfo = rechargePortInfoMapper.selectByImeiAndPortNo(simId, sendMessage.getPortNo());
                    if(rechargePortInfo!=null){
                        rechargePortInfo.setStatus(portStatus);
                        rechargePortInfoMapper.updateByPrimaryKeySelective(rechargePortInfo);
                    }
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //设置工作模式
    private void terminalSetWorkMode(Message msg){
        Qy_05 qy05 = (Qy_05) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy05.getReturnRes();
        try {
            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);

                    int workingMode = qy05.getWorkingMode();
                    if(workingMode>0){
                        workingMode--;
                    }

                    RechargeStationInfo rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
                    if(rechargeStationInfo!=null){
                        rechargeStationInfo.setStatus(workingMode);
                        rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
                    }
                    //待完成
                    //更新用户信息，更新交易信息
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //停止充电
    private void terminalChargeStop(Message msg){
        Qy_07 qy07 = (Qy_07) msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy07.getReturnRes();
        try {
            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);

                    RechargeStationInfo rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
                    if(rechargeStationInfo!=null){
                        int portIdelNo = rechargeStationInfo.getPortIdleNum()+1;
                        rechargeStationInfo.setStatus(1);
                        rechargeStationInfo.setPortIdleNum(portIdelNo);
                        rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
                    }

                    //待完成
                    //更新用户信息，更新交易信息
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //充电使能
    private void terminalChargeEnable(Message msg){
        Qy_06 qy06 = (Qy_06)msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        String random = String.format("%02X", msg.getHeader().getMessageSerialNo());
        int returnRes = qy06.getReturnRes();
        try {

            SendMessage sendMessage = sendMessageMapper.selectByImeiAndRandom(simId,random);
            if(sendMessage!=null){
                if(returnRes==0){
                    Date dt = new Date();
                    sendMessage.setIsSuccess(1);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);

                    RechargeStationInfo rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
                    if(rechargeStationInfo!=null){
                        int portIdelNo = rechargeStationInfo.getPortIdleNum()-1;
                        rechargeStationInfo.setPortIdleNum(portIdelNo);
                        rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
                    }

                    RechargePortInfo rechargePortInfo = rechargePortInfoMapper.selectByImeiAndPortNo(simId, sendMessage.getPortNo());
                    if(rechargePortInfo!=null){
                        rechargePortInfo.setRechargeMode(sendMessage.getRechargeMode());
                        rechargePortInfo.setStatus(2);
                        rechargePortInfoMapper.updateByPrimaryKeySelective(rechargePortInfo);
                    }



                    if(sendMessage.getUserId()!=null){
                        int userId = sendMessage.getUserId();
                        TransRecordInfo transRecordInfo = transRecordInfoMapper.getTransRecordInfo(userId,simId,sendMessage.getPortNo(),0,2);
                        if(transRecordInfo!=null){
                            transRecordInfo.setTransFlag(1);
                            transRecordInfo.setBorrowDateTime(dt);
                            transRecordInfoMapper.updateByPrimaryKeySelective(transRecordInfo);
                        }

                        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
                        if(userInfo!=null){
                            userInfo.setBorrowTime(dt);
                            userInfo.setAccountStatus(2);
                            userInfoMapper.updateByPrimaryKeySelective(userInfo);
                        }
                    }
                }else{
                    sendMessage.setIsSuccess(2);
                    sendMessageMapper.updateByPrimaryKeySelective(sendMessage);

                    //待完成
                    //需要处理用户信息，交易记录，退款
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //开始交易
    private void terminalStartTrans(Message msg){
        Qy_08 qy08 = (Qy_08)msg.getMessageContents();
        String simId = msg.getHeader().getSimId();

        int userId = qy08.getUserId();
        int portNo = qy08.getPortNo();
        String strStartDate = qy08.getStartChargingTime();
        try {
            if(userId==0){
                Date startDate = new Date();
                try {
                    startDate = dateFormat.parse(strStartDate);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                TransRecordInfo transRecordInfo = new TransRecordInfo();
                transRecordInfo.setImeiNo(simId);
                transRecordInfo.setPortNo(portNo);
                transRecordInfo.setBorrowDateTime(startDate);
                transRecordInfo.setCreateTime(startDate);
                transRecordInfo.setCreateBy("SYSTEM");
                transRecordInfo.setUserId(userId);
                transRecordInfo.setState(1);
                transRecordInfoMapper.insertSelective(transRecordInfo);

                RechargeStationInfo rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
                if(rechargeStationInfo!=null){
                    rechargeStationInfo.setPortIdleNum(rechargeStationInfo.getPortIdleNum()-1);
                    rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //结束交易
    private void terminalEndTrans(Message msg){
        Qy_09 qy09 = (Qy_09)msg.getMessageContents();
        String simId = msg.getHeader().getSimId();
        int userId = qy09.getUserId();
        int portNo = qy09.getPortNo();
        String strEndDate = qy09.getEndChargingTime();
        int endReason = qy09.getEndReason();


        try {
            RechargePortInfo rechargePortInfo = rechargePortInfoMapper.selectByImeiAndPortNo(simId,portNo);
            if(rechargePortInfo!=null){
                rechargePortInfo.setBatteryVoltage("0");
                rechargePortInfo.setBatteryElectric("0");
                rechargePortInfo.setStatus(1);
                rechargePortInfoMapper.updateByPrimaryKeySelective(rechargePortInfo);
            }
            Date dt = new Date();
            Date endDate = dt;
            try {
                endDate = dateFormat.parse(strEndDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            TransRecordInfo transRecordInfo = transRecordInfoMapper.getTransRecordInfo(userId, simId, portNo,1,2);
            if(transRecordInfo!=null){
                transRecordInfo.setTransFlag(2);
                transRecordInfo.setRecessionDateTime(endDate);
                transRecordInfoMapper.updateByPrimaryKeySelective(transRecordInfo);
            }

            UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
            if(userInfo!=null){
                userInfo.setAccountStatus(0);
                userInfoMapper.updateByPrimaryKeySelective(userInfo);
            }

            if(transRecordInfo!=null&&endReason<=20){
                try {
                    JSONObject backResult = JSONObject.parseObject(HttpRequest.sendGet(Constant.GET_TOKEN_HOST.toString(), null));
                    String access_token = (String) backResult.get("access_token");
                    String sendUrl = Constant.SEND_TOKEN_HOST+access_token;

                    JSONObject node = new JSONObject();
                    node.put("touser", userInfo.getOpenId());
                    node.put("template_id", Constant.TEMPLATE_NORMAL_ID);
                    node.put("form_id", transRecordInfo.getPrepayId());

                    DateFormat dtFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

                    JSONObject node2 = new JSONObject();
                    JSONObject node3 = new JSONObject();
                    node3.put("value", dtFormat.format(transRecordInfo.getBorrowDateTime()));

                    System.out.println("------------------------"+dtFormat.format(transRecordInfo.getBorrowDateTime()));
                    node2.put("keyword1", node3);
                    node3 = new JSONObject();
                    node3.put("value", dtFormat.format(transRecordInfo.getRecessionDateTime()));
                    node2.put("keyword2", node3);
                    node3 = new JSONObject();
                    node3.put("value", transRecordInfo.getRechargeTime()+"分钟");
                    node2.put("keyword3", node3);
                    node3 = new JSONObject();
                    node3.put("value", transRecordInfo.getTransMoney()+"元");
                    node2.put("keyword4", node3);
                    node3 = new JSONObject();
                    node3.put("value", "充电已完成，祝您一路顺风，欢迎下次使用！");
                    node2.put("keyword5", node3);
                    node.put("data", node2);

                    String content = node.toString();
                    System.out.println("------------------------"+content);

                    try {
                        backResult = JSONObject.parseObject(CommonUtils.readContentFromPost(sendUrl,content));
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            if(transRecordInfo!=null&&endReason>20){
                try {
                    JSONObject backResult = JSONObject.parseObject(HttpRequest.sendGet(Constant.GET_TOKEN_HOST.toString(), null));
                    String access_token = (String) backResult.get("access_token");
                    String sendUrl = Constant.SEND_TOKEN_HOST+access_token;

                    JSONObject node = new JSONObject();
                    node.put("touser", userInfo.getOpenId());
                    node.put("template_id", Constant.TEMPLATE_EXCEP_ID);
                    node.put("form_id", transRecordInfo.getPrepayId());


                    JSONObject node2 = new JSONObject();
                    JSONObject node3 = new JSONObject();
                    node3.put("value", "充电站已停止充电");
                    node2.put("keyword1", node3);
                    node3.put("value", "充电站温度过高");
                    node2.put("keyword2", node3);
                    node3.put("value", "请联系客服处理");
                    node2.put("keyword3", node3);
                    node.put("data", node2);

                    String content = node.toString();
                    try {
                        backResult = JSONObject.parseObject(CommonUtils.readContentFromPost(sendUrl,content));
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //心跳
    private void terminalTime(Message msg){
        Qy_04 qy04 = (Qy_04)msg.getMessageContents();
        String simId = msg.getHeader().getSimId();

        int csq = qy04.getCsq();
        int status = qy04.getWorkingMode();
        if(status>0){
            status--;
        }

        int portStatus = 0;
        int portBatteryElectric = 0;
        int portBatteryVoltage = 0;
        int portBatteryTemperature = 0;

        int portNum = qy04.getPortNum();
        RechargeStationInfo rechargeStationInfo = null;
        try {
            int portIdleNum = 0;
            Date dt = new Date();
            RechargePortInfo rechargePortInfo = null;
            List<Qy_04_SON> qy04SonsList  = qy04.getQy04SonsList();
            Qy_04_SON qy04Son = null;
            for(int i=1;i<=portNum;i++){
                qy04Son = qy04SonsList.get(i-1);
                rechargePortInfo = rechargePortInfoMapper.selectByImeiAndPortNo(simId,i);
                if(rechargePortInfo!=null){
                    portStatus = qy04Son.getPortStatus();
                    portBatteryElectric = qy04Son.getPortBatteryElectric();
                    portBatteryVoltage = qy04Son.getPortBatteryVoltage();
                    portBatteryTemperature = qy04Son.getPortBatteryTemperature();

                    rechargePortInfo.setStatus(portStatus);
                    rechargePortInfo.setBatteryElectric(String.valueOf(portBatteryElectric));
                    rechargePortInfo.setBatteryVoltage(String.valueOf(portBatteryVoltage));
                    rechargePortInfo.setBatteryTemperature(String.valueOf(portBatteryTemperature));
                    rechargePortInfoMapper.updateByPrimaryKeySelective(rechargePortInfo);

                    if(portStatus==1){
                        portIdleNum ++ ;
                    }
                }
            }

            rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
            if(rechargeStationInfo!=null){
                rechargeStationInfo.setCsq(csq);
                rechargeStationInfo.setLastConnectTime(dt);
                rechargeStationInfo.setIsonline(1);
                rechargeStationInfo.setStatus(status);
                rechargeStationInfo.setPortIdleNum(portIdleNum);
                rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //注册
    private void terminalRegister(Message msg){
        Qy_01 qy01 = (Qy_01)msg.getMessageContents();
        String simId = msg.getHeader().getSimId();

        String iccidNo = qy01.getIccid();
        int portTotalNum = qy01.getChargeNum();
        RechargeStationInfo rechargeStationInfo = null;
        try {
            rechargeStationInfo = rechargeStationInfoMapper.selectByImeiNo(simId);
            Date dt = new Date();
            if(rechargeStationInfo==null){
                rechargeStationInfo = new RechargeStationInfo();
                rechargeStationInfo.setImeiNo(simId);
                rechargeStationInfo.setIccidNo(iccidNo);
                rechargeStationInfo.setAuthCode(redisUtil.getValuesStr(simId));
                rechargeStationInfo.setLastConnectTime(dt);
                rechargeStationInfo.setStatus(0);
                rechargeStationInfo.setChargeType(0);
                rechargeStationInfo.setPortTotalNum(portTotalNum);
                rechargeStationInfo.setCreateTime(dt);
                rechargeStationInfo.setCreateBy("SYSTEM");
                rechargeStationInfoMapper.insertSelective(rechargeStationInfo);

                RechargePortInfo rechargePortInfo = null;
                for(int i=1;i<=portTotalNum;i++){
                    rechargePortInfo = new RechargePortInfo();
                    rechargePortInfo.setPortNo(i);
                    rechargePortInfo.setImeiNo(simId);
                    rechargePortInfo.setStatus(0);
                    rechargePortInfo.setCreateTime(dt);
                    rechargePortInfo.setCreateBy("SYSTEM");
                    rechargePortInfoMapper.insertSelective(rechargePortInfo);
                }
            }else{
                rechargeStationInfo.setImeiNo(simId);
                rechargeStationInfo.setIccidNo(iccidNo);
                rechargeStationInfo.setAuthCode(redisUtil.getValuesStr(simId));
                rechargeStationInfo.setCreateTime(dt);
                rechargeStationInfo.setCreateBy("SYSTEM");
                rechargeStationInfo.setLastConnectTime(dt);
                rechargeStationInfo.setStatus(0);
                rechargeStationInfo.setChargeType(0);
                rechargeStationInfo.setPortTotalNum(portTotalNum);
                rechargeStationInfoMapper.updateByPrimaryKeySelective(rechargeStationInfo);


            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
